/**
 * Created by dylan_Apple on 17/6/19.
 * 晨会信息表
 */
var Waterline = require('waterline');
var uuid = require('node-uuid');
var moment = require('moment');

/**
 * @type {void|*}
 */
module.exports = Waterline.Collection.extend({
    identity: 'mconference',
    tableName: 'tb_mconference',
    connection: "mysql",
    attributes: {

        rowId: {
            type: 'string',
            primaryKey: true,
            unique: true,
            required: true,
            uuidv4: true,
            columnName: 'rowid',
            defaultsTo: function () {
                return uuid.v4();
            }
        },
        seller: {
            type: 'string',
            required: true,
            columnName: 'seller',
            model: 'seller'
        },
        quotation:{
            type:'string',
            columnName:'quotation',
        },
        industry: {
            type: 'string',
            columnName: 'industry',
            model: 'industry'
        },
        createUid: {
            type: 'string',
            required: true,
            columnName: 'createuid',
            model: 'user'
        },
        date: {
            type: 'string',
            required: true,
            columnName: 'date'
        },
        timePlan: {
            type: 'string',
            columnName: 'timeplan'
        },
        type: {
            type: 'string',
            columnName: 'type'
        },
        corePoint: {
            type: 'string',
            columnName: 'corepoint'
        },
        analyst: {
            type: 'string',
            columnName: 'analyst',
            model: 'user'
        },
        contact: {
            type: 'string',
            columnName: 'contact'
        },
        status: {
            type: 'string',
            columnName: 'status'
        },
        reason: {
            type: 'string',
            columnName: 'reason'
        },
        companyRecommend: {
            type: 'string',
            columnName: 'companyrecommend'
        },
        /**
         * 股票集合
         */
        recommends: {
            collection: 'stockrecommend',
            via: 'actionId'
        },
        /**
         * 评论
         */
        comments: {
            collection: 'comment',
            via: 'mconference'
        },
        toJSON: function () {
            var obj = this.toObject();
            obj.createdAt = moment(obj.createdAt).format('YYYY-MM-DD HH:mm');
            obj.updatedAt = moment(obj.updatedAt).format('YYYY-MM-DD HH:mm');
            return obj;
        }

    }
});
